package com.study.util;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.study.model.pojo.Dictionary;
import com.study.services.CustomerService;
import com.study.services.DictionaryService;
import com.study.services.OrderService;

@WebListener
public class JTQListener implements ServletContextListener{
	@Autowired
	DictionaryService dictionService;
	@Autowired
	CustomerService customerService;
	@Autowired
	OrderService orderService;
	
	/**
	 * 服务器一开始便加载的数据
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		// TODO Auto-generated method stub
		
		System.out.println("我开始运行了,,,,,,,,,,,,,,,,");
		ServletContext application = sce.getServletContext();
		List<Dictionary> findByAll = dictionService.findByAll();
		String jsonString = JSON.toJSONString(findByAll);
		JSONArray  parse = JSONArray.parseArray(jsonString);
		// 查询字典表信息
		application.setAttribute("dictionaryitem",parse);
		
		
		
		// 查询可见客户信息
		List<JSONObject> selectAll = customerService.selectAll();
		Times.formatDate(selectAll, "cus_credate");
		application.setAttribute("mansitem",selectAll);
	
		//查询商品树形数据
		JSONArray findByTree = orderService.findByTree();
		application.setAttribute("treeitems",findByTree);
		
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
		System.err.println("出来了结束了");
		
	}

}
